/**
 * Created by yunpeng on 2015/4/9.
 */
var Table = require('../utils/Table').Table;
var Line = function(startstation,endstation,price,userid,createtime) {

    this.startstation = startstation;
    this.endstation = endstation;
    this.userid = userid;
    this.price = price;
    this.createtime = createtime;
    Line.prototype.save = function(data,callback){
        new Table('line').insert(data,function(err){
            if(err){
                callback(false);
            }else{
                callback(true);
            }
        });
    };
    if(typeof this.getLine !='function'){
        Line.prototype.getLine=function(arrs,callback){
            new Table().executeSql(" select * FROM line l WHERE l.userid=(?) ORDER BY createtime ",arrs,function(err,result){
                if(err){
                    callback(['']);
                }else{
                    callback(result);
                }
            });
        }
    }
    if(typeof this.validation!='function'){
        Line.prototype.validation=function(arrs,callback){
            new Table().executeSql(" select * FROM line l WHERE l.userid=(?) AND l.startstation=(?) AND l.endstation=(?) ORDER BY createtime ",arrs,function(err,result){
                if(err){
                    callback(['']);
                }else{
                    callback(result);
                }
            });
        }
    }
    if(typeof this.deleteLine !='function'){
        Line.prototype.deleteLine=function(id,callback){
            new Table('line').delete(" id ",id,function(err,result){
                if(err){
                    callback(err);
                }else{
                    callback(result);
                }
            });
        }
    }
}
exports.Line = Line;